/**
 * 
 */
package com.p2p.base.service.impl;

import java.io.Serializable;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import com.p2p.base.service.ProducerService;

/**
 * @author ruiqi
 *
 */
@Service("producerService")
public class ProducerServiceImpl implements ProducerService{

	private final Logger logger = LoggerFactory.getLogger(ValidateCodeSendServiceImpl.class);
	
	@Autowired(required=false)
	private JmsTemplate jmsTemplate;
	
	public void sendMessage(Destination destination, final Serializable object) {  
	    if(jmsTemplate==null){
	    	logger.error("jmsTemplate null");
	    	return;
	    }
        jmsTemplate.send(destination, new MessageCreator() {  
            public Message createMessage(Session session) throws JMSException {  
                return session.createObjectMessage(object);
            }  
        });  
    }
	
}
